package com.hiwhitley.algorithm.sort;

/**
 * Created by hiwhitley on 16-12-19.
 */
public class InsertionSort extends BaseSort{

    public static void sort(Comparable[] a) {
        int N = a.length;
        for (int i = 1; i < N; i++) {
            for (int j = i; j > 0 &&  less(a[j], a[j - 1]); j--) {
                exch(a, j, j - 1);
            }
        }
    }

    public static void main(String[] args) {
        String[] strings = new String[]{"c", "b", "a"};
        sort(strings);
        show(strings);
    }
}
